<script setup>
import { ref } from 'vue'
import { getCodeService, cheatPayService } from '@/api/borrowOrder.js'
import payImg from '@/assets/img/wechatPayment.jpg'
const dialogVisible = ref(false)
const deposit = ref(1000)
const id = ref('')
const codeUrl = ref('')
const formRef = ref()

const emit = defineEmits(['success'])
const getCode = async () => {
  await getCodeService(id.value, '微信支付')
}

// const waitPay = async () => {
//   await waitPayService(id.value, '微信支付')
//   dialogVisible.value = false
//   emit('success')
// }

const cheatPay = async () => {
  await cheatPayService(id.value)
  dialogVisible.value = false
  emit('success')
}

// 组件对外暴露一个方法 open，基于open传来的参数，区分添加还是编辑
// open({})  => 表单无需渲染，说明是添加
// open({ id, cate_name, ... })  => 表单需要渲染，说明是编辑
// open调用后，可以打开弹窗
const open = (row) => {
  dialogVisible.value = true
  deposit.value = row.deposit
  id.value = row.id
  getCode()
  codeUrl.value = payImg
  //waitPay()
}
// 向外暴露方法
defineExpose({
  open
})
</script>

<template>
  <el-dialog v-model="dialogVisible" :title="'支付页面'" width="30%">
    <el-form ref="formRef" label-width="100px" style="padding-right: 30px">
      <el-form-item
        ><img v-if="codeUrl" :src="codeUrl" class="book-pic"
      /></el-form-item>
      <el-form-item label="请支付：">{{ deposit }}元 </el-form-item>
      <el-form-item
        ><el-button @click="cheatPay">一键支付</el-button></el-form-item
      >
    </el-form>
  </el-dialog>
</template>

<style lang="scss" scoped>
.book-pic {
  width: 278px;
  height: 278px;
  display: block;
}
</style>
